<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button>显示欢迎词</button>
<h2 id="t1"></h2>
</body>
<script>
    let btn = document.getElementsByTagName('button')[0];
    btn.onclick = function () {
        let xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState==4 && xhr.status==200){
                document.getElementById('t1').innerHTML = xhr.responseText;
            }
        }
        xhr.open('get','test.php',true);//true异步
        xhr.send(null);
    }
</script>
</html>